import sys
sys.path.append("/home/roosevelt/Desktop/bayes/trunk/modules/")
from BayesNetwork import BayesNetwork

# ALARM
BN = BayesNetwork()
BN.parse("/home/roosevelt/Desktop/bayes/trunk/data/EncogBayesData/alarm.eg")
bn = BN.BayesianNetwork

variables, data = BN.loadDataset("/home/roosevelt/Desktop/bayes/trunk/data/dataset/alarm_500_perc1_missing_data.txt")
ESS_all, combinations = BN.computeAllESS(variables, data, bn)
BN.adjacencies_dict= None
for i in range(5):
    new_bn = BN.copy(bn)
    for j in range(3):
        new_bn = BN.randomPerturbation(new_bn, ESS_all, "VentLung", 2, False)
    new_bn = BN.laplaceSmoothBNParams(new_bn, BN.very_small_value)
    BN.export_encog("./alarm_ini_structure_lc"+str(i)+".eg", new_bn)
     
     
# CHILD    
BN.parse("/home/roosevelt/Desktop/bayes/trunk/data/EncogBayesData/child.bif")
bn = BN.BayesianNetwork
 
variables, data = BN.loadDataset("/home/roosevelt/Desktop/bayes/trunk/data/dataset/child_500_perc1_missing_data.txt")
ESS_all, combinations = BN.computeAllESS(variables, data, bn)
BN.adjacencies_dict= None
for i in range(5):
    new_bn = BN.copy(bn)
    for j in range(3):
        new_bn = BN.randomPerturbation(new_bn, ESS_all, "CO2", 2, False)
    new_bn = BN.laplaceSmoothBNParams(new_bn, BN.very_small_value)
    BN.export_encog("./child_ini_structure_lc"+str(i)+".eg", new_bn)
     
# INSURANCE
BN.parse("/home/roosevelt/Desktop/bayes/trunk/data/EncogBayesData/insurance.bif")
bn = BN.BayesianNetwork
 
variables, data = BN.loadDataset("/home/roosevelt/Desktop/bayes/trunk/data/dataset/insurance_500_perc1_missing_data.txt")
ESS_all, combinations = BN.computeAllESS(variables, data, bn)
BN.adjacencies_dict= None
for i in range(5):
    new_bn = BN.copy(bn)
    for j in range(3):
        new_bn = BN.randomPerturbation(new_bn, ESS_all, "SocioEcon", 2, False)
    new_bn = BN.laplaceSmoothBNParams(new_bn, BN.very_small_value)
    BN.export_encog("./insurance_ini_structure_lc"+str(i)+".eg", new_bn)
    
# HAILFINDER
BN.parse("/home/roosevelt/Desktop/bayes/trunk/data/EncogBayesData/hailfinder.eg")
bn = BN.BayesianNetwork

variables, data = BN.loadDataset("/home/roosevelt/Desktop/bayes/trunk/data/dataset/hailfinder_500_perc1_missing_data.txt")
ESS_all, combinations = BN.computeAllESS(variables, data, bn)
BN.adjacencies_dict= None
for i in range(5):
    new_bn = BN.copy(bn)
    for j in range(3):
        new_bn = BN.randomPerturbation(new_bn, ESS_all, "LLIW", 2, False)
    new_bn = BN.laplaceSmoothBNParams(new_bn, BN.very_small_value)
    BN.export_encog("./hailfinder_ini_structure_lc"+str(i)+".eg", new_bn)